
<template>
  <div class="login">
    <div class="box">
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <h3>欢迎登录--MMAIL管理系统</h3>

        <el-form-item prop="pass">
          <el-input type="text" v-model="ruleForm.username" autocomplete="off" placeholder="用户名"></el-input>
        </el-form-item>

        <el-form-item prop="checkPass">
          <el-input type="password" v-model="ruleForm.psw" autocomplete="off" placeholder="密码"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="login()">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
// import { Request } from "@/until/request";
import { login } from "@/request/http";

export default {
  name: "Login",
  data() {
    //获取输入内容--并规定
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入账户"));
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      }
    };
    return {
      ruleForm: {
        username: "admin",
        psw: "admin"
      },
      username: "",
      psw: "",
      rules: {
        pass: [{ validator: validatePass, trigger: "blur" }],
        checkPass: [{ validator: validatePass2, trigger: "blur" }]
      },
       local: { userToken: false }
    };
  },

  methods: {
     //登录
    login() {
       
        // Request.getData({
        //   url:  `/api/user/login.do?username=${this.ruleForm.username}&password=${this.ruleForm.psw}`,
        //   method:"post"
        // })
        login(this.ruleForm)
        .then(data=>{
            console.log(data)
            if(data.data.status==0){
              this.$message(data.data.msg);
              // this.local.userToken=true;
              // localStorage.setItem("admin",JSON.stringify(this.local))
              localStorage.setItem("admin",this.ruleForm.username)
              this.$router.push("/");
            }
            else{
              this.$message(data,data.msg)
            }
        })
    }
  },
  created(){
    //  localStorage.setItem("admin",JSON.stringify(this.local));
  }
};
</script>
<style>
.el-button {
  width: 100%;
}
</style>